﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tsgl
{
    public partial class logIn : Form
    {
        public logIn()
        {
            InitializeComponent();
        }

        //public string username, userpurview;
        private void btnLogin_Click(object sender, EventArgs e)
        {

            if (this.userName.Text == "" | this.passWord.Text == "")
            {
                MessageBox.Show("用户名或密码不能为空！","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else
            {
                DataTable dt = bookDbClass.ExecuteDataTable("select * from 用户信息 where 用户名=@un", new System.Data.SqlClient.SqlParameter("un", userName.Text));
                if (dt.Rows.Count <= 0)
                {
                    MessageBox.Show("用户名不存在！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataRow row = dt.Rows[0];
                    string dbpassword = Convert.ToString(row["密码"]);
                    if (dbpassword == passWord.Text)
                    {
                        string username = this.userName.Text.ToString();
                        string userpurview = row["用户类型"].ToString();
                        mainForm mainform = new mainForm(username,userpurview);
                        mainform.Show();
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("密码错误", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void passWord_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            this.AcceptButton = this.btnLogin;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}